﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BUS;
using DTO;

namespace GUI
{
    public partial class frmPhanCong : Form
    {
        public frmPhanCong()
        {
            InitializeComponent();
        }

        private void frmPhanCong_Load(object sender, EventArgs e)
        {
            HienThiDanhSach();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            frmThemPhanCong frm = new frmThemPhanCong();
            frm.ShowDialog();
        }

        public void HienThiDanhSach()
        {
            LichLamViecBUS llvBUS = new LichLamViecBUS();
            List<LichLamViecDTO> listLLV = new List<LichLamViecDTO>();
            LichLamViecDTO llvDTO = new LichLamViecDTO();
            try
            {
                listLLV = llvBUS.LayDanhSachLichLamViec();
                this.dgvDanhSach.Rows.Clear();
                for (int i = 0; i < listLLV.Count; i++)
                {
                    llvDTO = listLLV[i];
                    String MaLLV = llvDTO.MaLLV.ToString();
                    String ThoiGianLamViec = llvDTO.ThoiGianLamViec.ToString();
                    String NgayLamViec = llvDTO.NgayLamViec.ToShortDateString();
                    String TinhTrang = llvDTO.TinhTrang2.ToString();
                    String MaNV = llvDTO.MaNV.ToString();
                    String TenNV = llvDTO.TenNV.ToString();
                    dgvDanhSach.Rows.Add(MaLLV, MaNV, TenNV, ThoiGianLamViec, NgayLamViec, TinhTrang);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi:" + ex.ToString());
            }
        }

        private void buttonX4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dgvDanhSach_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }
            int intIndex = e.RowIndex;
            dgvDanhSach.Rows[intIndex].Selected = true;
        }
    }
}
